using UnityEngine;
using System;
using WolfCarol.AvgToolkit.Command;
using WolfCarol.AvgToolkit.Save;

namespace WolfCarol.AvgToolkit.Examples
{
    [Serializable]
    public class ScreenplayData
    {
        public string Path;

        public int Index;

        public bool CanExecute;

        public ScreenplayData()
        {
            Path = string.Empty;
            Index = 0;
            CanExecute = false;
        }
    }

    public class ScreenplayPresenter : CommandManager, ISavable<ScreenplayData>
    {
        public void Clear()
        {
            m_screenplay = null;
            m_index = 0;
            m_canExecute = false;
        }

        public ScreenplayData Save()
        {
            return new ScreenplayData()
            {
                Path = m_screenplay ? m_screenplay.name : string.Empty,
                Index = m_index,
                CanExecute = m_canExecute
            };
        }

        public void Load(ScreenplayData obj)
        {
            m_screenplay = Resources.Load<TextAsset>(obj.Path);
            SetScreenplay(m_screenplay?.text);
            m_index = obj.Index;
            m_canExecute = obj.CanExecute;
        }
    }
}